<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller 
{
    var $helpers = array('Html', 'Form', 'Session', 'Js','Javascript');
    var $components = array('Session','Auth','Cookie');
    var $uses= array('Z1user','Hocky','Tgiachidoan','Phanquyen');
    function beforeFilter(){
        	$this->Auth->authenticate = ClassRegistry::init('User');
            $user = $this->Auth->user();
         
            if(empty($user) && $this->params['action'] != 'login'){
                $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
       	$this->Auth->loginAction 	= array('controller' => 'users', 'action' => 'login');
		$this->Auth->loginRedirect 	= array('controller'=>'pages', 'action' => 'home');
		$this->Auth->loginError 	= 'Tài khoản hoặc mật khẩu sai';
		$this->Auth->authError 		= 'Bạn phải đăng nhập mới có thể sử dụng chức năng';
		$this->Auth->logoutRedirect = '/';
        $this->set('hockyht',$this->gethockyht());
    }

    function getHocKyHt(){
        $hockyht=$this->Hocky->find('first',array('conditions'=>array('active'=>1)));
        return $hockyht;           
    }
    //function getCDSV(){
//        $cdsv=$this->Tgiachidoan->find('first',array('conditions'=>array('sinhvien_id'=>'1'),'recursive'=>-1));
//        return $cdsv;
//    }      
   
 function beforeRender() {
		
        $curUser=$this->Auth->user();
        if(count($curUser)>0){
            $user=$this->Z1user->find('first', array('conditions'=>array('Z1user.id'=>$curUser['User']['id']),'recursive'=>1));
            $this->Session->write('userid',$user['Z1user']['id']);
            $this->Session->write('chucvid',$user['Z1user']['chucv_id']);
            $this->Session->write('khoa_id',$user['Z1user']['khoa_id']);
            $this->Session->write('chidoanht_id',$user['Z1user']['chidoansv_id']);
            $phanquyen=$this->Phanquyen->find('all',array('conditions'=>array('user_id'=>$user['Z1user']['id']),
                                                        'fields'=>'role_id'));
            
            $this->set(compact('user','phanquyen','curUser'));
            //debug($curUser);
           }

        $hockyhientai= $this->Hocky->query("SELECT * FROM hockies, namhocs
                                    where datediff(now(),ngaybatdau)>=0
                                    and datediff(ngayketthuc,now())>=0
                                    and hockies.namhoc_id=namhocs.id");
        if(count($hockyhientai)>0){
        $this->Session->write('hockyht_id',$hockyhientai[0]['hockies']['id']);
        $this->Session->write('hockyht_ten',$hockyhientai[0]['hockies']['tenhocky']);
        $this->Session->write('namhocht_id',$hockyhientai[0]['hockies']['namhoc_id']);
        $this->Session->write('namhocht_ten',$hockyhientai[0]['namhocs']['namhoc']);
        }
        
}

/**
  * tin thong bao
  * @var Tinthongbao 
  */
   var $Tinthongbao;
   /**
  * xem tin thong bao
  * @var Xemtinthongbao 
  */
   var $Xemtinthongbao;  
   /**
  * Z1sinhvien
  * @var Z1sinhvien  Model 
  */
   var $Z1sinhvien;  
  /**
  * Thoi gian dong doan phi khoa
  * @var Tgdongdoanphikhoa  Model 
  */
   var $Tgdongdoanphikhoa;  
 /**
  * Thoi gian dong doan phi
  * @var Tgdongdoanphisv Model 
  */
   var $Tgdongdoanphisv;
 /**
  * Sinh vien
  * @var Sinhvien Model 
  */
    var $Sinhvien;
  /**
   * Tham gia chi doan
   * @var Tgiachidoan Model
   */
    var $Tgiachidoan;
    /**
     * Thoi Gian Dong Doan phi can bo
     * @var Tgdongdoanphicb Model
     */
    var $Tgdongdoanphicb;
  /**
   * Thang
   * @var Thang;
   */
    var $Thang;
    
    /**
     * Doan phi sinh vien
     * @var Doanphisv
     */
	var $Doanphisv;    
    /**
     * Nam hoc
     * @var Namhoc
     */
	var $Namhoc;
	
	/**
	 * Can bo
	 * @var Canbo
	 */
	var $Canbo;
	
	/**
	 * Tham gia chi doan can bo
	 *
	 * @var Tgiachidoancb Model
	 */
	var $Tgiachidoancb;
	
	/**
	 * Doan phi sinh vien
	 * @var Doanphicb Model
	 */
	var $Doanphicb;
	
	/**
	 * Phi chi doan sinh vien
	 * @var Phicdsv Model 
	 */
	
	var $Phicdsv;
	
	/**
	 * Phi chi doan can bo
	 * @var Phicdcb Model 
	 */
	var $Phicdcb;
	
	/**
	 * Phong trao sinh vien
	 * @var Phongtraosv Model 
	 */
	var $Phongtraosv;
	
	/**
	 * Phong trao can bo
	 * @var Phongtraocb Model 
	 */
	var $Phongtraocb;
	
	/**
	 * Phong trao khoa sinh vien
	 * @var Phongtraokhoa Model 
	 */
	var $Phongtraokhoa;
	
	/**
	 * thanh tich sinh vien
	 * @var Thanhtichsv Model 
	 */
	var $Thanhtichsv;
	
	/**
	 * thanh tich can bo
	 * @var Thanhtichcb Model 
	 */
	var $Thanhtichcb;
	
	/**
	 * thanh tich khoa sinh vien
	 * @var Thanhtichkhoasv Model 
	 */
	var $Thanhtichkhoasv;
	
	/**
	 * thanh tich khoa can bo
	 * @var Thanhtichkhoacb Model 
	 */
	var $Thanhtichkhoakhoacb;
	
	/**
	 * Hoc Ky
	 * @var Hocky
	 */
	var $Hocky;
	
	/**
	 * quyet dinh ket nap
	 * @var Qdketnap Model
	 */
	var $Qdketnap;
	
	/**
	 * ket nap doan vien
	 * @var Ketnapdv Model
	 */
	var $Ketnapdv;
	
	/**
	 * chi doan
	 * @var Chidoansv
	 */
	var $Chidoansv;
	
	/**
	 * khen thuong ky luat
	 * @var Khenthuongkyluat
	 */
	var $Khenthuongkyluat;
	
	/**
	 * cap
	 * @var Cap
	 */
	var $Cap;
	
	/**
	 * Hinh thuc
	 * @var Hinhthuc
	 */
	var $Hinhthuc;
	
	/**
	 * Loai
	 * @var Loai
	 */
	var $Loai;
	
	/**
	 * Tinhtp
	 * @var Tinhtp
	 */
	var $Tinhtp;
	
	/**
	 * Quan huyen
	 * @var Quanhuyen
	 */
	var $Quanhuyen;
	
	/**
	 * Phuong xa
	 * @var Phuongxa
	 */
	var $Phuongxa;
	
	/**
	 * Dantoc
	 * @var Dantoc
	 */
	var $Dantoc;
	
	/**
	 * Tongiao
	 * @var Tongiao
	 */
	var $Tongiao;
	
	/**
	 * chi phi khoa
	 * @var Chiphikhoa
	 */
	var $Chiphikhoa;
	
	/**
	 * Loai chi phi
	 * @var Loaichiphi
	 */
	var $Loaichiphi;
	
	/**
	 * khoa
	 * @var Khoa
	 */
	var $Khoa;
	
	/**
	 * khoahoc
	 * @var Khoahoc
	 */
	var $Khoahoc;
	
	/**
	 * Nganh
	 * @var Nganh
	 */
	var $Nganh;
	
	/**
	 * Xep loai
	 * @var Xeploai
	 */
	var $Xeploai;
	
	/**
	 * user
	 * @var User
	 */
	var $User;
	
	/**
	 * Phan quyen
	 * @var Phanquyen
	 */
	var $Phanquyen;
	/**
	 * chuc vusv
	 * @var Chucvusv
	 */
	var $Chucvusv;
	/**
	 * chuc vu can bo
	 * @var Chucvucb
	 */
	var $Chucvucb;
	/**
	 * chuc vu 
	 * @var Chucv
	 */
	var $Chucv;
	/**
	 * Tap tin 
	 * @var Taptin
	 */
	var $Taptin;
	/**
	 * Role
	 * @var Role
	 */
	var $Role;
	
	/**
 * RequestHandlerComponent
 *
 * @var RequestHandlerComponent
 */
  var $RequestHandler;
	
	/**
	 * @var SessionComponent Component
	 */
	var $Session;
	
	/**
	 * @var CookieComponent
	 */
	var $Cookie;
}